﻿using MediatR;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.Command.DeepProce
{
    public class GetDeepCommandHand : IRequestHandler<GetDeepCommand, ApiResult<DeepProcessingModel>>
    {
        private readonly IBaseRepository<DeepProcessingModel> _deep;

        public GetDeepCommandHand(IBaseRepository<DeepProcessingModel> deep)
        {
            _deep = deep;
        }

        public Task<ApiResult<DeepProcessingModel>> Handle(GetDeepCommand request, CancellationToken cancellationToken)
        {
           var result=new ApiResult<DeepProcessingModel>();

            var deep = _deep.GetAll().FirstOrDefault(x => x.Batch == request.batch);
            if (deep != null)
            {
                result.data = deep;
            }
            return Task.FromResult(result);
        }
    }
}
